#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 2e3 + 10;

int n, p[2][N], f[N][N];

namespace T {
	int tr[N << 1];
	void add(int x, int v) { for(; x <= n + n; x += x & -x) tr[x] += v; }
	int query(int x) { int res = 0; for(; x; x -= x & -x) res += tr[x]; return res;}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in;
	rep(i, 1, n + n) {
		char ch = getchar(); while(!isalpha(ch)) ch = getchar();
		p[ch == 'B'][in] = i; 
	}
	memset(f, 0x3f, sizeof f);
	f[0][0] = 0;
	rep(i, 1, 2 * n) T :: add(i, 1);
	rep(i, 0, n) {
		if(i) T :: add(p[0][i], -1);
		rep(j, 0, n) {
			if(j) T :: add(p[1][j], -1);
			if(i) f[i][j] = min(f[i][j], f[i - 1][j] + T :: query(p[0][i] - 1));
			if(j) f[i][j] = min(f[i][j], f[i][j - 1] + T :: query(p[1][j] - 1));
		}
		rep(j, 1, n) T :: add(p[1][j], 1); 
	}
	printf("%d\n", f[n][n]);
	return 0;
}
